<template>
	<view class="content">
		<Header title="创建或绑定账号" :showBack='true'></Header>
		<view class="logo">
			<image :src="info.userinfo.avatar" style="width: 124rpx;height: 124rpx;" mode=""></image>
		</view>
		<view class="name">
			{{info.userinfo.nickname || ''}}
		</view>
		<button class="phone-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">授权手机号</button>
	</view>
</template>

<script>
	import Header from '@/components/header.vue'
	export default {
		data() {
			return {
				info: {
					userinfo:{}
				}
			}
		},
		onLoad() {
			this.info = uni.getStorageSync('bindInfo')
		},
		components: {
			Header
		},
		methods: {
			// 获取手机号
			getPhoneNumber(e){
				if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
					this.$u.toast('授权拒绝，请重试')
				} else{
					uni.login({
						provider: 'weixin',
						// onlyAuthorize: true,
						success: (res) => {
							let pramas = {
								code: res.code,
								encryptedData:e.detail.encryptedData,
								iv: e.detail.iv,
								userinfo:this.info
							}
							uni.$u.http.post('/login/getWechatMobile', pramas).then(bindRes => {
								this.$u.toast('登录成功')
								uni.setStorageSync('token', bindRes.data.token)
								uni.removeStorageSync('bindInfo')
								uni.navigateBack({
									delta:2
								})
							})
						}
					})
					
					
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		align-items: center;
		flex-direction: column;
	}

	.logo {
		margin-top: 114rpx;
		border-radius: 62rpx;
		overflow: hidden;
	}
	.name{
		margin-top: 22rpx;
	}

	.phone-btn {
		margin-top: 80rpx;
		width: 572rpx;
		height: 84rpx;
		background: #D8D8D8 linear-gradient(136deg, #FFECCA 0%, #E7BC70 100%);
		border-radius: 42rpx;
		border: none !important;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
		line-height: 84rpx;
	}
	.phone-btn::after{
		border: none !important;
	}
</style>
